﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Profile;
using LSData;
using LSEntity;
using LSInterFace;

namespace LSBLL
{
    public static class TestBLL
    {
        public static TestOTCurrent TestOTCurrent
        {
            get
            {
                return
                    HttpContext.Current.Request.RequestContext.HttpContext.Profile[WebConfig.TestOTCookieName] as
                    TestOTCurrent;
            }
            set
            {
                if (value != null && value.TestClassEntity != null)
                {
                    if (TestOTCurrent == null ||
                        TestOTCurrent.TestClassEntity == null ||
                        TestOTCurrent.TestClassEntity.TestId != value.TestClassEntity.TestId)
                    {
                        value.QuestionTypeList = QuestionBLL.QuestionTypeForOTGetList(value.TestClassEntity.TestId);
                        value.QuestionForOTList = QuestionBLL.QuestionForOTGetList(value.TestClassEntity.TestId)
                                                             .QuestionForOTListSetGroup();
                        value.TestEntity = TestGet(value.TestClassEntity.TestId);
                    }
                    else
                    {
                        value = TestOTCurrent;
                    }
                }
                HttpContext.Current.Request.RequestContext.HttpContext.Profile[WebConfig.TestOTCookieName] = value;
                HttpContext.Current.Request.RequestContext.HttpContext.Profile.Save();
            }
        }

        public static List<TestEntity> TestGetList(this TestGetEntity arge)
        {
            return TestData.TestGetList(arge);
        }

        public static TestEntity TestGet(int testId)
        {
            return TestData.TestGetList(new TestGetEntity
                                            {
                                                TestId = testId
                                            }).FirstOrDefault();
        }

        public static bool TestSetClass(this TestClassEntity testClassEntity)
        {
            return TestData.TestSetClass(testClassEntity);
        }

        public static TestClassEntity TestGetClassSet(int testId, int accountId)
        {
            return TestData.TestGetClassGet(testId, accountId);
        }

        public static List<TestClassEntity> TestGetClassGetList(int classId)
        {
            return TestGetClassGetList(new List<int> { classId });
        }

        public static List<TestClassEntity> TestGetClassGetList(List<int> classIds)
        {
            return TestData.TestGetClassGetList(classIds);
        }
    }
}
